﻿using System;
using System.IO;

namespace CsharpTrainer.Core.Log
{
    public class FileLog : IMyLog
    {
        public string LogFolder = "C:\\MyLog\\";
        public string FileBase = "AppLog";
        public string FileExtension = ".log";
        public string Content { get; set; }
        
        public void PrintLog()
        {
            //if log folder not exists create
            if (!Directory.Exists(LogFolder))
                Directory.CreateDirectory(LogFolder);

            string fileName = LogFolder + FileBase + DateTime.Now.ToString("yyyyMMdd") + FileExtension;
            FileStream fs;
            if (!File.Exists(fileName))
                fs = new FileStream(fileName, FileMode.Create);
            else
                fs = new FileStream(fileName, FileMode.Append);
            StreamWriter streamWriter = new StreamWriter(fs);
            streamWriter.BaseStream.Seek(0, SeekOrigin.End);
            streamWriter.WriteLine(Content);
            streamWriter.Flush();
        }
    }
}
